<?php 
function BuildListNewsLetter()
{
    global $dbsql,$language,$posts_per_page;
    
    $sql_where  = " from tblnewsletter where iStatus=1 ";
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    $countall   = $result['count'];
    list($lf,$la)= Split_Page($countall);
    
    $sql_select = "select * ".$sql_where." order by iId desc limit $lf,$la";
    $rs         = $dbsql->query($sql_select);
    
    $urlnewsletter  = getUrlCatByType('newsletter');
    
    $html           = '';
    while($result=$dbsql->fetch_array($rs))
    {
        $imglink        = GetIntroImg($result['cImageThumb'],true);
        $link           = $urlnewsletter.'/'.$result['cUrlString'];
        $html  .= '<div class="listnews">';
        $html  .= '<div class="img"><img src="'.$imglink.'" width="100%" /></div>';
        $html  .= '<a class="tt" onclick="openpopup(\''.$link.'\',800,700)">'.$result['cName'].'</a>';
        $html  .= '<div class="msg">'.strSplitSub($result['cDescription'],90).'</div>';
        $html  .= '<div class="clear"></div></div>';             
    } 
    $html      .= '<div class="clear">&nbsp;<br />&nbsp;</div> ';
    return $html;
}

function SendFriend()
{
    $email      = gpc_getStringPost('youremail');
    $name       = gpc_getStringPost('yourname');
    $email1     = gpc_getStringPost('email1');
    $email2     = gpc_getStringPost('email2');
    $email3     = gpc_getStringPost('email3');
    $msg        = gpc_getStringPost('message');
    $newsname   = gpc_getStringPost('newsname');
    
    ImportClass('account');
    if(!isValidEmail($email))
    {
        $err    = getLang('Please enter your email');
    }
    else if(empty($name))
    {
        $err    = getLang('Please enter your name');
    }
    else if(!isValidEmail($email1))
    {
        $err    = getLang('Please enter your friend\'s email');
    }
    $urlnewsletter= str_replace('sendfriend','',$_SERVER['HTTP_REFERER']);
    $newsletter = file_get_contents($urlnewsletter);
    
    $configemail= getConfigEmail('SendFriend');
    
    $title      = $configemail->title;
    $title      = str_replace('{EMAILCUSTOMER}',$email,$title);
    $title      = str_replace('{NAMECUSTOMER}',$name,$title);
    $title      = str_replace('{TITLENEWSLETTER}',$newsname,$title);
    
    $message    = $configemail->content;
    $message    = str_replace(array('<p>','</p>'),array('',''),$message);
    $message    = str_replace('{NAMECUSTOMER}',$name,$message);
    $message    = str_replace('{EMAILCUSTOMER}',$email,$message);
    $message    = str_replace('{MESSAGE}',$msg,$message);
    $message    = str_replace('{NEWSLETTER}',$newsletter,$message);
    $FooterMsg   = '<DIV  style="padding-top:10px">Happy travels,<br><b>The Team at Grandeur Journeys</b></DIV>';
    $message     = str_replace('<FOOTERMSG/>',$FooterMsg,$message);
    $arrBcc     = array();
    if(isValidEmail($email2))
    {
        $arrBcc[] = $email2;
    }
    if(isValidEmail($email3))
    {
        $arrBcc[] = $email3;
    }
    
    send_email($email1,"",$title,$message,$arrBcc);
    
    $success        = getLang('Thanks! An email has been sent to your friend(s)');
    if(!empty($err))
    {
        gpc_setSession('MsgError',$err);
    }else
    {
        gpc_setSession('SendFriendSuccess',$success);
    }
    
    $url        = $_SERVER['HTTP_REFERER'];
    Redirect($url);
}
?>